package com.wangjiangwen.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wangjiangwen.bean.R;
import com.wangjiangwen.bean.introduce.SaveIntroduceDTo;
import com.wangjiangwen.entity.Introduce;
import com.wangjiangwen.service.IntroduceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author gavin
 * @since 2024-07-05
 */
@RestController
@RequestMapping("/introduce")
public class IntroduceController {
    @Resource
    IntroduceService introduceService;

    @PostMapping("/save")
    public R<Void> save(@RequestBody SaveIntroduceDTo saveIntroduceDTo) {
        introduceService.lambdaUpdate()
                .set(Introduce::getContent, saveIntroduceDTo.getContent())
                .set(Introduce::getUpdateTime, new Date())
                .eq(Introduce::getType, saveIntroduceDTo.getType())
                .update();
        return R.ok("保存成功");
    }

    @GetMapping("/get")
    public R<Object> getRecruit(@RequestParam Integer type) {
        Introduce introduce = introduceService.getOne(Wrappers.<Introduce>lambdaQuery().eq(Introduce::getType, type));
        return R.ok((Object) introduce.getContent());
    }
}
